using Microsoft.EntityFrameworkCore;
using CMS_Admin.Backend.Api.Entity;

namespace CMS_Admin.Backend.Api.Db
{
    public class AdminDb : DbContext
    {
        // 因为我们使用AddDbContext到容器，所以此处必须得有带参数的构造函数（而且必须传递DbContextOptions类型的参数，同时父类也得调用这个参数）
        public AdminDb(DbContextOptions options) : base(options)
        {

        }

        public DbSet<Users> Users { get; set; }
        public DbSet<Roles> Roles { get; set; }
        public DbSet<UserRoles> UserRoles { get; set; }
        public DbSet<ArticleClass> ArticleClass { get; set; }
        public DbSet<Articles> Articles { get; set; }
        public DbSet<Comments> Comments { get; set; }
        public DbSet<Jurisdiction> Jurisdictions { get; set; }
        public DbSet<Likes> Likes { get; set; }
        public DbSet<OtherInfo> OtherInfo { get; set; }
        public DbSet<Resource> Resource { get; set; }
        public DbSet<RolesJurisdiction> RolesJurisdiction { get; set; }
        public DbSet<UserArticles> UserArticles { get; set; }
        public DbSet<WebsiteInfo> websiteInfo { get; set; }
        public DbSet<AuditInfo> AuditInfo { get; set; }



        // 游
        protected override void OnConfiguring(DbContextOptionsBuilder builder)
            => builder.UseSqlServer(@"server=LAPTOP-NT2O3C2R\SQLEXPRESS;database=CMS;uid=xiaoyou;pwd=5a2699yu;");
 
        //    protected override void OnConfiguring(DbContextOptionsBuilder options)
        //     => options.UseNpgsql(@"User ID=postgres;Password=5a2699yu;Host=8.129.43.230;Port=5432;Database=CMSDatabase");



        protected override void OnModelCreating(ModelBuilder model)
        {
            model.Entity<Jurisdiction>().HasData(
                new Jurisdiction
                {
                    Id = 1,
                    JurisdictionName = "无"
                },
                new Jurisdiction
                {
                    Id = 2,
                    JurisdictionName = "所有权限"
                },
                new Jurisdiction
                {
                    Id = 3,
                    JurisdictionName = "基本权限"
                },
                new Jurisdiction
                {
                    Id = 4,
                    JurisdictionName = "用户权限"
                },
                new Jurisdiction
                {
                    Id = 5,
                    JurisdictionName = "文章权限"
                },
                new Jurisdiction
                {
                    Id = 6,
                    JurisdictionName = "角色权限"
                },
                new Jurisdiction
                {
                    Id = 7,
                    JurisdictionName = "图片权限"
                }

            );



            model.Entity<Roles>().HasData(
               new Roles
               {
                   Id = 1,
                   RoleName = "普通用户"
               },
               new Roles
               {
                   Id = 2,
                   RoleName = "管理员"
               },
               new Roles
               {
                   Id = 3,
                   RoleName = "超级管理员"
               }

           );


            model.Entity<RolesJurisdiction>().HasData(
                new RolesJurisdiction
                {
                    Id = 1,
                    RolesId = 1,
                    JurisdictionId = 1


                },
                new RolesJurisdiction
                {
                    Id = 2,
                    RolesId = 2,
                    JurisdictionId = 3
                },
                new RolesJurisdiction
                {
                    Id = 3,
                    RolesId = 3,
                    JurisdictionId = 2
                }

            );


            model.Entity<ArticleClass>().HasData(
               new ArticleClass
               {
                   Id = 1,
                   ArticleClassName = "新闻"
               },
               new ArticleClass
               {
                   Id = 2,
                   ArticleClassName = "热点"
               }
           );

            model.Entity<Resource>().HasData(
                new Resource
                {
                    Id = 1,
                    ResoutceName = "https://img1.baidu.com/it/u=3886212450,854269223&fm=26&fmt=auto&gp=0.jpg"

                },
                new Resource
                {
                    Id = 2,
                    ResoutceName = "https://img1.baidu.com/it/u=3044261220,3500389775&fm=26&fmt=auto&gp=0.jpg"
                }

            );
           
            // model.Entity<Articles>().HasData(
            //     new Articles
            //     {
            //         Id = 1,
            //         ArticleTitle = "大反垄断法",
            //         ArticleClassId = 1,
            //         ResourceId=1
            //     }

            // );

            model.Entity<Users>().HasData(
                new Users
                {
                    Id = 1,
                    Nickname = "小可爱",
                    Username = "xiaoyou",
                    Password = "123456",
                    RolesId = 3,
                    Txcolor="white",
                    Bgcolor="blue"


                },
                new Users
                {
                    Id = 2,
                    Nickname = "嘿",
                    Username = "xiaoai",
                    Password = "123456",
                    RolesId = 1,
                    Txcolor="white",
                    Bgcolor="blue"

                }


            );




            model.Entity<OtherInfo>().HasData(
                new OtherInfo
                {
                    Id=1,
                    InfoName="微信url",
                    InfoContent="http://dds",
                    WebsiteInfoId=1
                }
            );


            model.Entity<WebsiteInfo>().HasData(
                new WebsiteInfo
                {
                    Id = 1,
                    Owner = "xiaoai",
                    Introduce = "就爱科技有限公司",
                    Phone = "15270759789",
                    Address = "福建省龙岩市新罗区",
                    Mailbox = "1254412212@qq.com",
                    Url = "www.9ihub.com",
                    WebsiteICP = "京ICP备12020869号-2",
                    PutOnRecords = "京公网安备44010602000207",
                   
                }

            );






        }






        //东
        // protected override void OnConfiguring(DbContextOptionsBuilder builder)
        //     => builder.UseSqlServer(@"server=.;database=CMS;uid=sa;pwd=123456;");


        //秀
        // protected override void OnConfiguring(DbContextOptionsBuilder builder)
        // => builder.UseSqlServer(@"server=DESKTOP-B0M4KE7;database=CMS;uid=sa;pwd=123456;");

        // 刘
        // protected override void OnConfiguring(DbContextOptionsBuilder builder)
        // => builder.UseSqlServer(@"server=LAPTOP-47B7TGQ4\SQLEXPRESS;database=CMS;uid=sa;pwd=123456;");



    }
}